﻿using CRMBiz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;
using CRMFramework;
using System.Collections;
using Newtonsoft.Json;
using CRMWeb.Utilities.Context;

namespace CRMWeb.WebServices
{
    /// <summary>
    /// Summary description for ApplicationProcessSelect
    /// </summary>
    public class ApplicationProcessSelect : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string input_type = string.IsNullOrEmpty(context.Request.QueryString["type"]) ? "" : context.Request.QueryString["type"].ToString();
                string input_appdate = string.IsNullOrEmpty(context.Request.QueryString["appdate"]) ? "" : context.Request.QueryString["appdate"].ToString();

                var pageIndex = string.IsNullOrEmpty(context.Request["page"]) ? 1 : int.Parse(context.Request["page"]);
                var pageSize = string.IsNullOrEmpty(context.Request["rows"]) ? 10 : int.Parse(context.Request["rows"]);


                DataSet ds = ApplicationProcessHandler.BindApplicationProcess(input_type, input_appdate, pageIndex, pageSize);
                var total = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
                string strJson = JsonConvert.SerializeObject(ds.Tables[0]);
                strJson = "{\"total\":\"" + total.ToString() + "\",\"rows\":" + strJson + "}";
                context.Response.Write(strJson);
            }
            catch (Exception ex) 
            {
                ErrorHandler.saveErrorLog(ex,CMSContext.CurrentUser.MemberName);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}